//点击可查询公司采购单详情
function checkCompanyDetails($purchaseId,$supplierId){
	var obj=$("#bag").html("");
	obj.load("companyPurchaseDetailMapping",function(response,status,xhr){
		var data="companyPurchaseInfoID="+$purchaseId+"&DetailsupplierId="+$supplierId+"&productName="+"&pages=";
		showAllCompanyPurchaseDetail(data);
		$("#purchaseNo").val($purchaseId);
		$("#supplierInfoPur").val($supplierId);
		getCompanyPurchaseNo($purchaseId,$supplierId);
		getSupplierObject($supplierId);
	})
}

//通过采购id和供应商id查询公司采购编号和采购日期
function getCompanyPurchaseNo($purchaseId,$supplierId){
	//获取提交路径
	var url="/trade-wzj-web/tests/getCompanyPurchaseNo";
	//获取参数
	var data="id="+$purchaseId+"&supplierId="+$supplierId;
	var obj=getUrlClientOrder(url,data,"POST");
	var or=$("#orderNo").html("");
	or.append(obj.purchaseNo);
	var od=$("#orderDates").html("");
	var st=$("#purchaseStartDate").html("");
	st.append(obj.purchaseDate);
	od.append(obj.purchaseDelivery);
}



//显示公司采购详情信息
function showAllCompanyPurchaseDetail($data){
	var obj=$("#companyPurchaseDetailTable tbody").html("");
	//获取路径
	var url="/trade-wzj-web/tests/getAllCompanyPurchaseInfos";
	//获取参数
	var data=$data;
	//定义字符串拼接
	var str="";
	//调用提交方法
	var result = postMethod(url,"POST",data);
	//获取状态结果集信息
	var states=getUrlClientOrder("/trade-wzj-web/StateControllerYang/findState","POST");
	var strs="<select class='form-control' style='text-align:center;width:3rem;margin:0px auto;' id='stateId'>" +
			"<option value=0>--请选择--</option>";
	for(var j=0;j<states.length;j++){
		strs=strs+"<option value='"+states[j].id+"'>" +
					states[j].stateInfo+
				"</option>";
	}
	strs=strs+"</select>";
	//获取集合
	var list=result.list;
	console.info(list);
	if(list.length==0){
		alert("对不起，查询数据不存在");
		return;
	}
	if(list.length>0){
		var k=1;
		for(var i=0;i<list.length;i++){
			str=str+"<tr>" +
						"<td><input type='hidden' id='companyPurchaseId' value='"+list[i].id+"'>"+(k)+"</td>"+
						"<td>"+list[i].productInfoQuota.productName+"</td>"+
						"<td></td>"+
						"<td>暂无</td>"+
						"<td>"+list[i].productNum+"</td>"+
						"<td>"+list[i].unit+"</td>"+
						"<td>"+list[i].productInfoQuota.productPrice+"</td>"+
						"<td>"+(list[i].productNum*list[i].productInfoQuota.productPrice)+"</td>"+
						"<td>"+list[i].state.stateInfo+"</td>"+
						"<td>"+strs+"</td>"+
						"<td><button class='btn btn-info' onclick='ensure("+list[i].id+")'>确定</button></td>"+
					"</tr>";
			k++;
		}
	}
	
	var page=$("#companyPurchaseDetailrPage").html("");
	//调用分页代码
	var va=companyPurchaseDetailPages(result);
	page.append(va);
	obj.append(str);
}

//获取页码信息
function companyPurchaseDetailPages($clientList){
	var page="";
	
	var con = $("#companyPurchaseNo").val();
	page = page+"<div class='row' style='margin:0px'>" +
	"<div class='col-md-2 col-sm-2 col-xs-2' style='padding-top:0.7rem'>"+
		"<span style='font-weight:bold'>总记录数 "+$clientList.total+"   |  总页数 "+$clientList.pages+"</span>"+
	"</div>"+
	"<div class='col-md-offset-8 col-sm-offset-8 col-xs-offset-8'>"
	+"<nav aria-label='Page navigation'>"+
"<ul class='pagination pagination-sm'>";
	if($clientList.prePage>0){
		page = page+"<li><a href='#' onclick='makeCompanyPurchaseDetailPages("+$clientList.firstPage+",\""+con+"\")'>首页</a></li>"+
		"<li><a href='#' onclick='makeCompanyPurchaseDetailPages("+$clientList.prePage+",\""+con+"\")'>上一页</a></li>";
				
	}
	if($clientList.nextPage<=$clientList.lastPage && $clientList.nextPage>0){
		page = page+"<li><a href='#' onclick='makeCompanyPurchaseDetailPages("+$clientList.nextPage+",\""+con+"\")'>下一页</a></li>"+
		"<li><a href='#' onclick='makeCompanyPurchaseDetailPages("+$clientList.lastPage+",\""+con+"\")'>末页</a></li>";
	}
	page = page+"</li>"+
"</ul>"+
"</nav>"+
"</div>"+
"</div>";
	return page;
	
}

//分页功能
function makeCompanyPurchaseDetailPages($page,$object){
	var data="companyPurchaseInfoID="+$("#purchaseNo").val()+"&DetailsupplierId="+$("#supplierInfoPur").val()+"&productName="+$object+"&pages="+$page;
	showAllCompanyPurchaseDetail(data);
}

//获取供应商信息
function getSupplierObject($supplierId){
	var url="/trade-wzj-web/SupplierInfoContrillerYang/getSupplierInfoById";
	var data="id="+$supplierId;
	var result = postMethod(url,"POST",data);
	//供应商名称
$("#supplierNames").html(result.supplierName);
//供应商联系人
$("#supplierPeople").html(result.supplierContacts);
//供应商联系方式
$("#supplierPhones").html(result.supplierPhone);
}

//确定按钮事件
function ensure($productId){
	//获取产品id值
	var productId=$productId;
	//获取供应商id值
	var supplierId=$("#supplierInfoPur").val();
	//获取状态值
	var state=$("#stateId").val();
	if(state==0){
		//状态为0时
	}else if(state==1){
		//状态为1时
	}else if(state==2){
		//状态为2时
	}else if(state==3){
		//状态为3时
	}else if(state==4){
		//状态为4时
	}else if(state==5){
		//状态为5时
	}else if(state==6){
		//状态为6时
	}else if(state==7){
		//状态为7时
	}else if(state==8){
		//状态为8时
	}else{
		//状态为9时
	}
}